﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL.MySQL;
using Models;
using PetaPoco;

namespace Core
{
    public class xinxiCore
    {
        private readonly xinxiDAL dal = new xinxiDAL();

        public xinxiEntity GetOne(int id)
        {
            return dal.GetOne(id) == null ? new xinxiEntity() : dal.GetOne(id);
        }

        public xinxiEntity GetOneByWhere(string where, string order, params object[] args)
        {
            var result = dal.GetOneByWhere(where, order, args);
            return result ?? new xinxiEntity();
        }
        public qxinxiModel GetQOne(int id)
        {
            return dal.GetQOne(id) == null ? new qxinxiModel() : dal.GetQOne(id);
        }
        public int UpdateHits(int ID)
        {
            return dal.UpdateHits(ID);
        }
        public int Update(object obj, int ID)
        {
            return dal.Update(obj, ID);
        }
        public qxinxiModel Save(qxinxiModel model)
        {
            return dal.Save(model);
        }
        public qxinxiModel GetQOneByTitle(string title)
        {
            return dal.GetQOneByTitle(title) == null ? new qxinxiModel() : GetQOneByTitle(title);
        }
        public List<cxinxiModel> GetList(int top,string where,string order,params object[] args)
        {
            if(top>0)
                return dal.GetPageList(1, top, where, order, args).Items;
            return dal.GetList(where, order, args);
        }
        public Page<cxinxiModel> GetPage(int page,int pagesize,string where ,string order, params object[] args)
        {
            return dal.GetPageList(page, pagesize, where, order, args);
        }
        public bool Del(int id)
        {
            return dal.Del(id);
        }
        public bool Del(xinxiEntity model)
        {
            return dal.Del(model);
        }
    }
}
